package com.tencreat.service.mall.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.utils.SecurityUtils;
import com.tencreat.domain.mall.MallSelfmention;
import com.tencreat.mapper.mall.MallSelfmentionMapper;
import com.tencreat.service.mall.IMallSelfmentionService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 自提地址Service业务层处理
 *
 * @author tencreat
 * @date 2022-01-05
 */
@Service
public class MallSelfmentionServiceImpl extends ServiceImpl<MallSelfmentionMapper, MallSelfmention> implements IMallSelfmentionService {


    /**
     * 查询自提地址
     *
     * @param id 自提地址ID
     * @return 自提地址
     */
    @Override
    public MallSelfmention selectMallSelfmentionById(ReqIdParam id) {
        return baseMapper.selectById(id.getId());
    }

    /**
     * 查询自提地址列表
     *
     * @param mallSelfmention 自提地址
     * @return 自提地址
     */
    @Override
    public List<MallSelfmention> selectMallSelfmentionList(MallSelfmention mallSelfmention) {
        return baseMapper.selectList(Wrappers.query(mallSelfmention));
    }

    /**
     * 新增自提地址
     *
     * @param mallSelfmention 自提地址
     * @return 结果
     */
    @Override
    public int insertMallSelfmention(MallSelfmention mallSelfmention) {
        mallSelfmention.setCreateTime(LocalDateTime.now());
        mallSelfmention.setCreateBy(SecurityUtils.getLoginUser().getUser().getUserName());
        mallSelfmention.setUserId(SecurityUtils.getLoginUser().getUser().getUserId());
        mallSelfmention.setDelFlag("0");
        return baseMapper.insert(mallSelfmention);
    }

    /**
     * 修改自提地址
     *
     * @param mallSelfmention 自提地址
     * @return 结果
     */
    @Override
    public int updateMallSelfmention(MallSelfmention mallSelfmention) {
        mallSelfmention.setUpdateTime(LocalDateTime.now());
        return baseMapper.updateById(mallSelfmention);
    }

    /**
     * 批量删除自提地址
     *
     * @param ids 需要删除的自提地址ID
     * @return 结果
     */
    @Override
    public int deleteMallSelfmentionByIds(ReqIdsParam ids) {
        return baseMapper.deleteBatchIds(ids.getId());
    }

    /**
     * 删除自提地址信息
     *
     * @param id 自提地址ID
     * @return 结果
     */
    @Override
    public int deleteMallSelfmentionById(ReqIdParam id) {
        return baseMapper.deleteById(id.getId());
    }
}
